******************************************************************
** title:	The Catholic Voter									**
** date:	Oct 26 2023 					  					**
** authors:	Daoust, Guévremont                      			**
******************************************************************

******************************************************************
** TO MERGE THE 2019 and 2021 CES								**
******************************************************************

******************************************
** FIRST, OPEN AND CLEAN THE 2019 CES	**
******************************************

*cd "/Users/daoj2702/Desktop/The Catholic Voter/"
*use "/Users/daoj2702/Desktop/The Catholic Voter/2019 Canadian Election Study - Online Survey v1.0.dta", clear


cd "C:\Users\melya\Documents\Université\Daoust\Blais 2005\Catholic voter"
use "C:\Users\melya\Documents\Université\Daoust\Blais 2005\2019 Canadian Election Study - Online Survey v1.0.dta", clear
*/

********Cleaning********
*Remove all the non-citizens from the dataset

drop if cps19_citizenship==5

************************
***Generate variables***
************************

********************
*Socio demographics*
********************

*Gender
gen woman=.
replace woman=0 if cps19_gender==1
replace woman=1 if cps19_gender==2

label define label_gender 0 "Man" 1 "Woman"
label values woman label_gender

*Generation 
gen generation=.
replace generation=1 if cps19_age<=26
replace generation=2 if cps19_age>26 & cps19_age<=42
replace generation=3 if cps19_age>42 & cps19_age<=58
replace generation=4 if cps19_age>58 & cps19_age<=75
replace generation=5 if cps19_age>75

label define label_gen_group 1 "Generation Z" 2 "Millennials" 3 "Generation X" 4 "Baby boomers" 5 "Silent Generation"
label values generation label_gen_group

*Age (categorical)
gen age_cat=. 
replace age_cat=1 if cps19_age>=18 & cps19_age<=34
replace age_cat=2 if cps19_age>=35 & cps19_age<=44
replace age_cat=3 if cps19_age>=45 & cps19_age<=65
replace age_cat=4 if cps19_age>65

label define label_age 1 "18-34" 2 "35-44" 3 "45-65" 4 "More than 65"
label values age_cat label_age

*Age (3 groups)
gen age_threegroups=. 
replace age_threegroups=1 if cps19_age>=18 & cps19_age<=35
replace age_threegroups=2 if cps19_age>=36 & cps19_age<=59
replace age_threegroups=3 if cps19_age>59

label define label_age_three 1 "18-35" 2 "36-59" 3 "60 and over"
label values age_threegroups label_age_three

*Age (dicho)
gen age_dicho=. 
replace age_dicho=1 if cps19_age>=18 & cps19_age<=35
replace age_dicho=2 if cps19_age>35

label define label_age_dicho 1 "18-35" 2 "36 and over"
label values age_dicho label_age_dicho


*Province of residence
gen prov=.   
replace prov=1 if cps19_province==15
replace prov=2 if cps19_province==14
replace prov=3 if cps19_province==25
replace prov=4 if cps19_province==16
replace prov=5 if cps19_province==22
replace prov=6 if cps19_province==24
replace prov=7 if cps19_province==17 | cps19_province==18 | cps19_province== 20| cps19_province==23

label define label_provinces 1 "BC" 2 "Alberta" 3 "Sask" 4 "Man" 5 "Ont" 6 "Qc" 7 "Eastern"
label values prov label_provinces

*Province of residence QC/ROC 
gen prov_qc=.
replace prov_qc=0 if cps19_province!=24
replace prov_qc=1 if cps19_province==24

label define label_province 0 "Rest of Canada" 1 "Quebec"
label values prov_qc label_province

*Post-sec diploma 
gen post_sec=.
replace post_sec=0 if cps19_education<=6
replace post_sec=1 if cps19_education>6 & cps19_education<=11

label define label_post_secondary 0 "No schooling, primary or high school" 1 "CÉGEP diploma or higher"
label values post_sec label_post_secondary

*Income 
gen income=.
replace income=1 if cps19_income_cat==1 & (cps19_income_number==0 | cps19_income_number==.) | cps19_income_cat==2 | ///
cps19_income_number>0 & cps19_income_number<=30000
replace income=2 if cps19_income_cat==3 | cps19_income_number>30000 & cps19_income_number<=60000
replace income=3 if cps19_income_cat==4 | cps19_income_number>60000 & cps19_income_number<=90000
replace income=4 if cps19_income_cat==5 | cps19_income_number>90000 & cps19_income_number<=110000
replace income=5 if cps19_income_cat==6 | cps19_income_number>110000 & cps19_income_number<=150000
replace income=6 if cps19_income_cat==7 | cps19_income_number>150000 & cps19_income_number<=200000
replace income=7 if cps19_income_cat==8 | inrange(cps19_income_number, 200000, 6750000000000000000000000000000000000000000000001) 

label define label_income 1 "<30,001" 2 "$30,001 to $60,000" 3 "$60,001 to $90,000" 4 "$90,001 to $110,000" 5 "$110,001 to $150,000" 6 "$150,001 to $200,000" 7 "More than $200,000"
label values income label_income

*Immigrant
gen imm=.
replace imm=0 if cps19_bornin_canada==1
replace imm=1 if cps19_bornin_canada==2

label define label_born_Canada 0 "Born in Canada" 1 "Not born in Canada"
label values imm label_born_Canada

*Religion
clonevar religion_brute=cps19_religion

gen catholic=.
replace catholic=0 if cps19_religion!=10
replace catholic=1 if cps19_religion==10
replace catholic=. if cps19_religion==23

label define label_religion 0 "Not Catholic" 1 "Catholic"
label values catholic label_religion


gen religion_cat=.
replace religion_cat=1 if inlist(cps19_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat=2 if cps19_religion==10
replace religion_cat=3 if cps19_religion==1 | cps19_religion==2
replace religion_cat=4 if inlist(cps19_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_1 1 "Protestant" 2 "Catholic" 3 "No religion or agnostic"  4 "Other"
label values religion_cat label_cat_religion_1


gen religion_cat_bprotestant=.
replace religion_cat_bprotestant=1 if inlist(cps19_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat_bprotestant=2 if cps19_religion==10
replace religion_cat_bprotestant=3 if cps19_religion==1 | cps19_religion==2
replace religion_cat_bprotestant=4 if inlist(cps19_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_2 1 "Protestant" 2 "Catholic" 3 "No religion or agnostic"  4 "Other"
label values religion_cat_bprotestant label_cat_religion_2


gen religion_cat_bcatho=.
replace religion_cat_bcatho=1 if cps19_religion==10
replace religion_cat_bcatho=2 if inlist(cps19_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat_bcatho=3 if cps19_religion==1 | cps19_religion==2
replace religion_cat_bcatho=4 if inlist(cps19_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_3 1 "Catholic" 2 "Protestant" 3 "No religion or agnostic"  4 "Other"
label values religion_cat_bcatho label_cat_religion_3


gen religion_cat_bnoreligion=.
replace religion_cat_bnoreligion=1 if cps19_religion==1 | cps19_religion==2
replace religion_cat_bnoreligion=2 if cps19_religion==10
replace religion_cat_bnoreligion=3 if inlist(cps19_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat_bnoreligion=4 if inlist(cps19_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_4 1 "No religion or agnostic" 2 "Catholic" 3 "Protestant" 4 "Other"
label values religion_cat_bnoreligion label_cat_religion_4


gen religion_cat_bother=.
replace religion_cat_bother=1 if inlist(cps19_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)
replace religion_cat_bother=2 if cps19_religion==10
replace religion_cat_bother=3 if cps19_religion==1 | cps19_religion==2
replace religion_cat_bother=4 if inlist(cps19_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)

label define label_cat_religion_5 1 "Other" 2 "Catholic" 3 "No religion or agnostic" 4 "Protestant"
label values religion_cat_bother label_cat_religion_5

*Religiosity
gen religiosity=. 
replace religiosity=0 if cps19_rel_imp==2 | cps19_rel_imp==3 | cps19_rel_imp==4
replace religiosity=1 if cps19_rel_imp==1

label define label_religiosity 0 "Not religious" 1 "Religious"
label values religiosity label_religiosity


gen religiosity_linear=.
replace religiosity_linear=0 if cps19_rel_imp==4
replace religiosity_linear=0.33 if cps19_rel_imp==3 & religion_cat!=3
replace religiosity_linear=0.67 if cps19_rel_imp==2 & religion_cat!=3
replace religiosity_linear=1 if cps19_rel_imp==1 & religion_cat!=3

replace religiosity_linear = 0 if religion_cat==3 // to put the agnostics or DK at 0 on religiosity


gen religiosity_dicho=.
replace religiosity_dicho=0 if religiosity_linear==0 | (cps19_rel_imp==3 & religion_cat!=3)
replace religiosity_dicho=1 if religiosity_linear==1 | (cps19_rel_imp==2 & religion_cat!=3)


gen religiosity_cat=.
replace religiosity_cat=1 if cps19_rel_imp==4
replace religiosity_cat=2 if cps19_rel_imp==3
replace religiosity_cat=3 if cps19_rel_imp==2
replace religiosity_cat=4 if cps19_rel_imp==1

label define label_importance 1 "Not important at all" 2 "Not very important" 3 "Somewhat important" 4 "Very important"
label values religiosity_cat label_importance 

*Attendance (religious service)
gen attendance_dicho=.
replace attendance_dicho=0 if inlist(pes19_service_freq, 1, 2) // never or once a year
replace attendance_dicho=1 if inlist(pes19_service_freq, 3, 4, 5, 6) // more than once a year

gen attendance_linear=.
replace attendance_linear=0 if pes19_service_freq==1 // never
replace attendance_linear=0.2 if pes19_service_freq==2 // Once a year
replace attendance_linear=0.4 if pes19_service_freq==3 // 2-11 times a year
replace attendance_linear=0.6 if pes19_service_freq==4 // Once a month
replace attendance_linear=0.8 if pes19_service_freq==5 // 2-3 times a month
replace attendance_linear=1 if pes19_service_freq==6 // Once a week or +

*Language 
**Survey language
gen survey_language=.
replace survey_language=0 if cps19_Q_Language=="EN"
replace survey_language=1 if cps19_Q_Language=="FR-CA"

label define label_lang1 0 "English" 1 "French"
label values survey_language label_lang1 


**Pre-election survey (language learned as a child)
gen mother_tongue=.
replace mother_tongue=0 if cps19_language_69==. & (cps19_language_68==1 | cps19_language_70==1 | cps19_language_71==1 | cps19_language_72==1 | cps19_language_73==1 | cps19_language_74==1 | cps19_language_75==1 | cps19_language_76==1 | cps19_language_77==1 | cps19_language_78==1 | cps19_language_79==1 | cps19_language_80==1 | cps19_language_81==1 | cps19_language_82==1 | cps19_language_83==1 | cps19_language_84==1 | cps19_language_85==1)
replace mother_tongue=1 if cps19_language_69==1

label define label_lang2 0 "Other" 1 "French"
label values mother_tongue label_lang2 


**Post-election survey (language spoken at home)
gen post_language=.
replace post_language=1 if pes19_lang==69
replace post_language=2 if pes19_lang==68 
replace post_language=3 if pes19_lang>69 & pes19_lang<=84

label define label_lang3 1 "French" 2 "English" 3 "Other"
label values post_language label_lang3

*Rural/urban
gen rural_urban=pes19_rural_urban
recode rural_urban 6=.

label define label_city_size 1 "A rural area or village (less than 1000 people)" 2 "A small town (more than 1000 people but less than 15K)" ///
3 "A middle-sized town (15K-50K people) not attached to a city" 4 "A suburb of a large town or city" 5 "A large town or city (more than 50K people)"
label values rural_urban label_city_size

*Weight
gen elecid=2019
gen weight=pes19_weight_general_all if elecid==2019

********************
**	Vote choice	  **
********************
clonevar vote_choice_brute=pes19_votechoice2019

*Vote choice
gen vote_choice=.
replace vote_choice=1 if pes19_votechoice2019==1
replace vote_choice=2 if pes19_votechoice2019==2
replace vote_choice=3 if pes19_votechoice2019==3
replace vote_choice=6 if pes19_votechoice2019==4
replace vote_choice=5 if pes19_votechoice2019==5
replace vote_choice=4 if pes19_votechoice2019==6

label define label_party 1 "LPC" 2 "CPC" 3 "NPD" 4 "PPC" 5 "Green" 6 "Bloc"
label values vote_choice label_party

*Vote Liberal
gen vote_lib=.
replace vote_lib=0 if pes19_votechoice2019>1 & pes19_votechoice2019<=8
replace vote_lib=1 if pes19_votechoice2019==1

label define label_lib 0 "Did not vote for the Liberal party" 1 "Voted for the Liberal party"
label values vote_lib label_lib
*DK/refusal are not included


************************
***Descriptive stats***
************************
eststo clear
estpost sum woman generation prov prov_qc post_sec income imm catholic ///
	religion_cat religion_cat_bprotestant religion_cat_bcatho religion_cat_bnoreligion religion_cat_bother ///
	religiosity religiosity_linear religiosity_dicho religiosity_cat survey_language mother_tongue post_language ///
	 rural_urban vote_choice vote_lib age_cat age_threegroups age_dicho religion_brute vote_choice_brute ///
	 attendance_dicho attendance_linear
esttab using "Descriptive_stats_CES19.rtf", cells("min max mean sd count") label mlabels(,titles) replace


**********************
** CLEAN DATASET	**
**********************

keep elecid woman generation prov prov_qc post_sec income imm religion_brute catholic ///
	religion_cat religion_cat_bprotestant religion_cat_bcatho religion_cat_bnoreligion religion_cat_bother ///
	religiosity religiosity_linear religiosity_dicho religiosity_cat survey_language mother_tongue post_language ///
	 rural_urban vote_choice_brute vote_choice vote_lib age_cat age_threegroups age_dicho attendance_dicho ///
	 attendance_linear weight 

save "ces2019_cleaned.dta", replace



******************************************************************
** 							BREAK								**
******************************************************************






******************************************************************
** 				OPEN AND CLEAN THE 2021 CES						**
******************************************************************

*cd "/Users/daoj2702/Desktop/The Catholic Voter/"
*use "/Users/daoj2702/Desktop/Automne 2023/melyann/Blais 2005 replication/Canadian Election Studies/CES2021/2021 Canadian Election Study v1.0.dta", clear


cd "C:\Users\melya\Documents\Université\Daoust\Blais 2005\Catholic voter"
use "C:\Users\melya\Documents\Université\Daoust\Blais 2005\2021 Canadian Election Study v1.0.dta", clear
*/

********Cleaning********
*Remove all the non-citizens from the dataset

drop if cps21_citizenship==2

************************
***Generate variables***
************************

********************
*Socio demographics*
********************

*Gender
gen woman=.
replace woman=0 if cps21_genderid==1
replace woman=1 if cps21_genderid==2

label define label_gender 0 "Man" 1 "Woman"
label values woman label_gender

*Generation 
gen generation=.
replace generation=1 if cps21_age<=26
replace generation=2 if cps21_age>26 & cps21_age<=42
replace generation=3 if cps21_age>42 & cps21_age<=58
replace generation=4 if cps21_age>58 & cps21_age<=75
replace generation=5 if cps21_age>75

label define label_gen_group 1 "Generation Z" 2 "Millennials" 3 "Generation X" 4 "Baby boomers" 5 "Silent Generation"
label values generation label_gen_group

*Age (categorical)
gen age_cat=. 
replace age_cat=1 if cps21_age>=18 & cps21_age<=34
replace age_cat=2 if cps21_age>=35 & cps21_age<=44
replace age_cat=3 if cps21_age>=45 & cps21_age<=65
replace age_cat=4 if cps21_age>65

label define label_age 1 "18-34" 2 "35-44" 3 "45-65" 4 "More than 65"
label values age_cat label_age

*Age (3 groups)
gen age_threegroups=. 
replace age_threegroups=1 if cps21_age>=18 & cps21_age<=35
replace age_threegroups=2 if cps21_age>=36 & cps21_age<=59
replace age_threegroups=3 if cps21_age>59

label define label_age_three 1 "18-35" 2 "36-59" 3 "60 and over"
label values age_threegroups label_age_three

*Age (dicho)
gen age_dicho=. 
replace age_dicho=1 if cps21_age>=18 & cps21_age<=35
replace age_dicho=2 if cps21_age>35

label define label_age_dicho 1 "18-35" 2 "36 and over"
label values age_dicho label_age_dicho

*Province of residence
gen prov=.   
replace prov=1 if cps21_province==2
replace prov=2 if cps21_province==1
replace prov=3 if cps21_province==12
replace prov=4 if cps21_province==3
replace prov=5 if cps21_province==9
replace prov=6 if cps21_province==11
replace prov=7 if cps21_province==4 | cps21_province==5 | cps21_province==7 | cps21_province==10

label define label_provinces 1 "BC" 2 "Alberta" 3 "Sask" 4 "Man" 5 "Ont" 6 "Qc" 7 "Eastern"
label values prov label_provinces

*Province of reisdence QC/ROC 
gen prov_qc=.
replace prov_qc=0 if cps21_province!=11
replace prov_qc=1 if cps21_province==11

label define label_province 0 "Rest of Canada" 1 "Quebec"
label values prov_qc label_province

*Post-sec diploma 
gen post_sec=.
replace post_sec=0 if cps21_education<=6
replace post_sec=1 if cps21_education>6 & cps21_education<=11

label define label_post_secondary 0 "No schooling, primary or high school" 1 "CÉGEP diploma or higher"
label values post_sec label_post_secondary

*Income in 2020
gen income=.
replace income=1 if cps21_income_cat==1 & (cps21_income_number==0 | cps21_income_number==-99)| cps21_income_cat==2 | ///
cps21_income_number>0 & cps21_income_number<=30000
replace income=2 if cps21_income_cat==3 | cps21_income_number>30000 & cps21_income_number<=60000
replace income=3 if cps21_income_cat==4 | cps21_income_number>60000 & cps21_income_number<=90000
replace income=4 if cps21_income_cat==5 | cps21_income_number>90000 & cps21_income_number<=110000
replace income=5 if cps21_income_cat==6 | cps21_income_number>110000 & cps21_income_number<=150000
replace income=6 if cps21_income_cat==7 | cps21_income_number>150000 & cps21_income_number<=200000
replace income=7 if cps21_income_cat==8 | cps21_income_number>200000

label define label_income 1 "<30,001" 2 "$30,001 to $60,000" 3 "$60,001 to $90,000" 4 "$90,001 to $110,000" 5 "$110,001 to $150,000" 6 "$150,001 to $200,000" 7 "More than $200,000"
label values income label_income

*Immigrant
gen imm=.
replace imm=0 if cps21_bornin_canada==1
replace imm=1 if cps21_bornin_canada==2

label define label_born_Canada 0 "Born in Canada" 1 "Not born in Canada"
label values imm label_born_Canada

*Religion
clonevar religion_brute = cps21_religion

gen catholic=.
replace catholic=0 if cps21_religion!=10
replace catholic=1 if cps21_religion==10
replace catholic=. if cps21_religion==23

label define label_religion 0 "Not Catholic" 1 "Catholic"
label values catholic label_religion


gen religion_cat=.
replace religion_cat=1 if inlist(cps21_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat=2 if cps21_religion==10
replace religion_cat=3 if cps21_religion==1 | cps21_religion==2
replace religion_cat=4 if inlist(cps21_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion 1 "Protestant" 2 "Catholic" 3 "No religion or agnostic" 4 "Other"
label values religion_cat label_cat_religion

gen religion_cat_bprotestant=.
replace religion_cat_bprotestant=1 if inlist(cps21_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat_bprotestant=2 if cps21_religion==10
replace religion_cat_bprotestant=3 if cps21_religion==1 | cps21_religion==2
replace religion_cat_bprotestant=4 if inlist(cps21_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_2 1 "Protestant" 2 "Catholic" 3 "No religion or agnostic"  4 "Other"
label values religion_cat_bprotestant label_cat_religion_2


gen religion_cat_bcatho=.
replace religion_cat_bcatho=1 if cps21_religion==10
replace religion_cat_bcatho=2 if inlist(cps21_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat_bcatho=3 if cps21_religion==1 | cps21_religion==2
replace religion_cat_bcatho=4 if inlist(cps21_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_3 1 "Catholic" 2 "Protestant" 3 "No religion or agnostic"  4 "Other"
label values religion_cat_bcatho label_cat_religion_3


gen religion_cat_bnoreligion=.
replace religion_cat_bnoreligion=1 if cps21_religion==1 | cps21_religion==2
replace religion_cat_bnoreligion=2 if cps21_religion==10
replace religion_cat_bnoreligion=3 if inlist(cps21_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)
replace religion_cat_bnoreligion=4 if inlist(cps21_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)

label define label_cat_religion_4 1 "No religion or agnostic" 2 "Catholic" 3 "Protestant" 4 "Other"
label values religion_cat_bnoreligion label_cat_religion_4


gen religion_cat_bother=.
replace religion_cat_bother=1 if inlist(cps21_religion, 3, 4, 5, 6, 7, 11, 12, 14, 22)
replace religion_cat_bother=2 if cps21_religion==10
replace religion_cat_bother=3 if cps21_religion==1 | cps21_religion==2
replace religion_cat_bother=4 if inlist(cps21_religion, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21)

label define label_cat_religion_5 1 "Other" 2 "Catholic" 3 "No religion or agnostic" 4 "Protestant"
label values religion_cat_bother label_cat_religion_5

*Religiosity
gen religiosity=. 
replace religiosity=0 if cps21_rel_imp==2 | cps21_rel_imp==3 | cps21_rel_imp==4
replace religiosity=1 if cps21_rel_imp==1

label define label_religiosity 0 "Not religious" 1 "Religious"
label values religiosity label_religiosity


gen religiosity_linear=.
replace religiosity_linear=0 if cps21_rel_imp==4 | religion_cat==3 // to put the agnostics or DK at 0 on religiosity
replace religiosity_linear=0.33 if cps21_rel_imp==3 & religion_cat!=3
replace religiosity_linear=0.67 if cps21_rel_imp==2 & religion_cat!=3
replace religiosity_linear=1 if cps21_rel_imp==1 & religion_cat!=3


gen religiosity_dicho=.
replace religiosity_dicho=0 if religiosity_linear==0 | (cps21_rel_imp==3 & religion_cat!=3)
replace religiosity_dicho=1 if religiosity_linear==1 | (cps21_rel_imp==2 & religion_cat!=3)


gen religiosity_cat=.
replace religiosity_cat=1 if cps21_rel_imp==4
replace religiosity_cat=2 if cps21_rel_imp==3
replace religiosity_cat=3 if cps21_rel_imp==2
replace religiosity_cat=4 if cps21_rel_imp==1

label define label_importance 1 "Not important at all" 2 "Not very important" 3 "Somewhat important" 4 "Very important"
label values religiosity_cat label_importance


*Attendance (religious service)
gen attendance_dicho=.
replace attendance_dicho=0 if inlist(pes21_service_freq, 1, 2) // never or once a year
replace attendance_dicho=1 if inlist(pes21_service_freq, 3, 4, 5, 6) // more than once a year

gen attendance_linear=.
replace attendance_linear=0 if pes21_service_freq==1 // never
replace attendance_linear=0.2 if pes21_service_freq==2 // Once a year
replace attendance_linear=0.4 if pes21_service_freq==3 // 2-11 times a year
replace attendance_linear=0.6 if pes21_service_freq==4 // Once a month
replace attendance_linear=0.8 if pes21_service_freq==5 // 2-3 times a month
replace attendance_linear=1 if pes21_service_freq==6 // Once a week or +


*Language
**Survey language
gen survey_language=.
replace survey_language=0 if Q_Language=="EN"
replace survey_language=1 if Q_Language=="FR-CA"

label define label_lang1 0 "English" 1 "French"
label values survey_language label_lang1 


**Pre-election survey (language learned as a child)
gen mother_tongue=.
replace mother_tongue=0 if cps21_language_2==-99
replace mother_tongue=1 if cps21_language_2==1

label define label_lang2 0 "Other" 1 "French"
label values mother_tongue label_lang2 


**Post-election survey (language spoken at home)
gen post_language=.
replace post_language=1 if pes21_lang==2
replace post_language=2 if pes21_lang==1 
replace post_language=3 if pes21_lang>2 & pes21_lang<=17

label define label_lang3 1 "French" 2 "English" 3 "Other"
label values post_language label_lang3

*Rural/urban
gen rural_urban=pes21_rural_urban
recode rural_urban 6=.

label define label_city_size 1 "A rural area or village (less than 1000 people)" 2 "A small town (more than 1000 people but less than 15K)" 3 "A middle-sized town (15K-50K people) not attached to a city" 4 "A suburb of a large town or city" 5 "A large town or city (more than 50K people)"
label values rural_urban label_city_size

*Weight
gen elecid=2021
gen weight=pes21_weight_general_all if elecid==2021

********************
**  Vote Choice	  **
********************
clonevar vote_choice_brute = pes21_votechoice2021

*Vote choice
gen vote_choice=.
replace vote_choice=1 if pes21_votechoice2021==1
replace vote_choice=2 if pes21_votechoice2021==2
replace vote_choice=3 if pes21_votechoice2021==3
replace vote_choice=6 if pes21_votechoice2021==4
replace vote_choice=5 if pes21_votechoice2021==5
replace vote_choice=4 if pes21_votechoice2021==6

label define label_party 1 "LPC" 2 "CPC" 3 "NPD" 4 "PPC" 5 "Green" 6 "Bloc"
label values vote_choice label_party

*Vote Liberal
gen vote_lib=.
replace vote_lib=0 if pes21_votechoice2021>1 & pes21_votechoice2021<=8
replace vote_lib=1 if pes21_votechoice2021==1

label define label_lib 0 "Did not vote for the Liberal party" 1 "Voted for the Liberal party"
label values vote_lib label_lib
*DK/refusal are not included

************************
***Descriptive stats***
************************
eststo clear
estpost sum woman generation prov prov_qc post_sec income imm catholic ///
	religion_cat religion_cat_bprotestant religion_cat_bcatho religion_cat_bnoreligion religion_cat_bother ///
	religiosity religiosity_linear religiosity_dicho religiosity_cat survey_language mother_tongue post_language ///
	 rural_urban vote_choice vote_lib age_cat age_threegroups age_dicho religion_brute vote_choice_brute ///
	 attendance_dicho attendance_linear
esttab using "Descriptives_stat_CES21.rtf", cells("min max mean sd count") label mlabels(,titles) replace


**********************
** CLEAN DATASET	**
**********************
keep elecid woman generation prov prov_qc post_sec income imm religion_brute catholic ///
	religion_cat religion_cat_bprotestant religion_cat_bcatho religion_cat_bnoreligion religion_cat_bother ///
	religiosity religiosity_linear religiosity_dicho religiosity_cat survey_language mother_tongue post_language ///
	 rural_urban vote_choice_brute vote_choice vote_lib age_cat age_threegroups age_dicho attendance_dicho ///
	 attendance_linear weight

save "ces2021_cleaned.dta", replace













******************************************************************
** 							BREAK								**
******************************************************************






**************************
** Append 2019 to 2021	**
**************************

*Get in the 2021 dataset
*use "/Users/daoj2702/Desktop/The Catholic Voter/ces2021_cleaned.dta", clear
use "\Users\melya\Documents\Université\Daoust\Blais 2005\Catholic voter\ces2021_cleaned.dta", clear

*Append
*append using "/Users/daoj2702/Desktop/The Catholic Voter/ces2019_cleaned.dta"
append using "C:\Users\melya\Documents\Université\Daoust\Blais 2005\Catholic voter\ces2019_cleaned.dta"

	
*Save the pooled dataset
save "pooled_ces2019-21.dta", replace

*Save the pooled dataset in the replication files folder
*cd "/Users/daoj2702/Desktop/The Catholic Voter/replication files /"
*save "pooled_ces2019-21.dta", replace

